//
//  WJUIButton+Blocks.m
//  verycloud
//
//  Created by 王军 on 16/7/26.
//  Copyright © 2016年 王军. All rights reserved.
//

#import "WJUIButton+Blocks.h"
#import <objc/runtime.h>

@implementation WJUIButton_Blocks

-(id)initWithBlock:(void(^)(void))block {
    self = [super init];
    if (self) {
        objc_setAssociatedObject(self, "WJUIButton_Blocks", [block copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
        [self addTarget:self action:@selector(callActionBlock:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

-(void)callActionBlock:(id)sender{
    if (sender == self) {
        void (^block)(void) = objc_getAssociatedObject(self, "WJUIButton_Blocks");
        if (block)
        {
            block();
        }
    }
}

@end
